![]() ![]() ![]() |
For example,
Object[] arr; Vector vector = new Vector(10, null); ... Algo.copy(Array.begin(arr), Array.end(arr), vector.begin());copies the elements in the array
arr
into the vector.
Array iterators exits for arrays of Object
, for the individual
characters in String
and StringBuffer
and for all the
primitive data types available in the java language.
Note that an arra iterator on a String
does not support the
put()
method, because String
s are immutable.
StringBuffer
however support put()
.
When an array iterator is used with an array of primitive data, a wrapper
object is created for each execution of the get()
method.
This makes array iterators very fine for creating objects based on data
in arrays, but they are rather slow when used for scanning through the
entire array and for updating the array.
The type wrapper used depends on the array type.
Primitive type | Wrapper class |
---|---|
byte
| Integer
|
short
| Integer
|
int
| Integer
|
float
| Float
|
double
| Double
|
char
| Character
|
boolean
| Boolean
|
![]() ![]() ![]() |